<style scoped>
.p_c1{
    width:50%;float: left;padding-left: 10px;
    span{line-height: 22px;}
}
.dis{color:#ccc;}
.pp_cc{min-height: 200px;text-align: center;line-height: 200px;position: relative;}
.div_cd1:after{content: "";display: block;clear: both;}
.div_cd2{float: right;width:250px;}
.div_cd2 p{line-height: 23px;}
.div_cd2 span{color:#e7922d;}
.p_cd1{float: left;padding-top:69px;}
.p_cd1 span{color:#e7922d;}
.div_cd3{position: absolute;left:50%;width:300px;margin-left:-150px;margin-top: 23px;
border-bottom: 2px #e7922d solid;}
.div_cd3 p{text-align: center;color:#e7922d;font-size:22px;font-weight: 400;
border-bottom: 2px #e7922d solid;margin-bottom: 2px;padding-bottom: 5px;}
</style>
<template>
<div>
     <Modal v-model="modal" :title="title" :styles="{width:'1150px',top:'20px'}" :mask-closable="false">
        <p class="p_c1">
            <b>销售方</b><br/>
            <span>名称:&nbsp;&nbsp;{{data.mainVo.XSF_MC}}</span><br/>
            <span>纳税人识别号:&nbsp;&nbsp;{{data.mainVo.XSF_NSRSBH}}</span><br/>
            <span>地 址、电 话:&nbsp;&nbsp;{{data.mainVo.XSF_DZDH}}</span><br/>
            <span>开户行及帐号:&nbsp;&nbsp;{{data.mainVo.XSF_YHZH}}</span><br/>
        </p> 
        <p><b>购买方</b> <br/>
            <span>名称:&nbsp;&nbsp;{{data.mainVo.GMF_MC}}</span><br/>
            <span>纳税人识别号:&nbsp;&nbsp;{{data.mainVo.GMF_NSRSBH}}</span><br/>
            <span>地 址、电 话:&nbsp;&nbsp;{{data.mainVo.GMF_DZDH}}</span><br/>
            <span>开户行及帐号:&nbsp;&nbsp;{{data.mainVo.GMF_YHZH}}</span><br/>
        </p>
        <p style="color:red;padding-left:10px;padding-top:10px;" 
        v-html="data.errorMsg">
            
        </p>
        <div style="margin-top:10px;">
            <div class="ivu-table-wrapper" >
                <div class="ivu-table ivu-table-with-fixed-top ">
                    <div class="ivu-table-body" >
                        <table  class="table_border _table1"   cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
                           
                            <thead>
                                <tr>
                                    <th class="" style="width:60px;"  v-if="data.needSplit=='Y'">
                                        <div class="ivu-table-cell">
                                            <span>勾选</span>
                                        </div>
                                    </th>
                                    <th class="" style="width:200px;">
                                        <div class="ivu-table-cell">
                                            <span>货物或应税劳务、服务名称</span>
                                        </div>
                                    </th>
                                    <th class="" style="width:100px;">
                                        <div class="ivu-table-cell">
                                            <span>规格型号</span>
                                        </div>
                                    </th>
                                    <th class=""  style="width:100px;">
                                        <div class="ivu-table-cell">
                                            <span>单位</span>
                                        </div>
                                    </th>
                                    <th class=""  style="width:100px;">
                                        <div class="ivu-table-cell">
                                            <span>数量</span>
                                        </div>
                                    </th>
                                    <th class="" style="width:100px;">
                                        <div class="ivu-table-cell">
                                            <span>单价</span>
                                        </div>
                                    </th>
                                    <th class="" style="width:100px;">
                                        <div class="ivu-table-cell">
                                            <span>  金额</span>
                                        </div>
                                    </th>
                                    <th class="" style="width:100px;">
                                        <div class="ivu-table-cell">
                                            <span>  税率</span>
                                        </div>
                                    </th>
                                    <th class="" style="width:100px;">
                                        <div class="ivu-table-cell">
                                            <span>  税额</span>
                                        </div>
                                    </th>
                                    <th class="" style="width:70px;"  v-if="data.needSplit=='Y'">
                                        <div class="ivu-table-cell">
                                            <span>操作</span>
                                        </div>
                                    </th>
                                </tr>
                            </thead>
                            <tbody class="ivu-table-tbody" v-for="item in data.detailList" :key="item.guid">
                                <tr class="ivu-table-row">
                                    <td class="" v-if="data.needSplit=='Y'">
			                            <div class="ivu-table-cell">
			                        		<Checkbox v-model="item.check" 
			                        		 name="radio_1"></Checkbox>
                                             
			                        	</div>
			                        </td>
                                    <td class="">
                                        <div class="ivu-table-cell">
                                            <span>{{item.goodsName}}</span>
                                        </div>
                                    </td>
                                    <td class="">
                                        <div class="ivu-table-cell">
                                            <span>{{item.goodsSpecification}}</span>
                                        </div>
                                    </td>
                                    <td class="">
                                        <div class="ivu-table-cell">
                                            <span>{{item.goodsUnit}}</span>
                                        </div>
                                    </td>
                                    <td class="">
                                        <div class="ivu-table-cell">
                                            <span>{{item.goodsQuantity}}</span>
                                        </div>
                                    </td>
                                    <td class="">
                                        <div class="ivu-table-cell">
                                           <span>{{item.goodsPrice}}元</span>
                                        </div>
                                    </td>
                                    <td class="">
                                        <div class="ivu-table-cell">
                                           <span>{{item.goodsTotalPrice}}元</span>
                                        </div>
                                    </td>
                                    <td class="">
                                        <div class="ivu-table-cell">
                                           <span>{{item.goodsTaxRate}}</span>
                                        </div>
                                    </td>
                                    <td class="">
                                        <div class="ivu-table-cell">
                                           <span>{{item.goodsTotalTax}}</span>
                                        </div>
                                    </td>
                                    <td  v-if="data.needSplit=='Y'">
                                        <div class="ivu-table-cell">
                                            <Button  v-on:click="marge(item)"   size="small"
                                            type="primary"
                                           v-if="item.orgGoodGuid!=null">合并</Button>
                                          <Button  v-on:click="split(item)" v-else

                                            size="small" type="error">拆分</Button>
                                          
                                        </div>
                                    </td>
                                    
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                
            </div>
        </div>       
         <div slot="footer">
             <Button @click="cancel()">关闭</Button>
             <Button @click="sub()" type="primary">开票</Button>
         </div>
     </Modal>
     <split-edit @refresh="getdata"></split-edit>
</div>
</template>
<script>
import SplitEdit from "./split.vue";
 export default {
     components:{SplitEdit},
     data (){
         return {
             modal:false,title:'开票预览',status:'',
             data:{mainVo:{},},guid:''
         }
     },methods:{
         showdata(params){
            this.guid=params.guid;
            this.data=params.data || {};
            this.modal=true;
            
            
            
         },
         marge(item){
            this.axios.post('/outputinoivce/splitBack',{
                goodGuid:item.guid
            }).then((res)=>{
                if(res.errorCode==0){
                    this.$Message.success(res.message);
                }else{
                    this.$Message.error(res.message);
                }
                this.getdata();
            })
         },
         getdata(){
            this.axios.post('/outputinoivce/invoicePreview',
                    [this.guid]).then((res)=>{
                console.log(res)
                if(res.errorCode==0){
                    //this.$Message.error(res.message);
                    //this.data=res.data
                    this.$set(this.data,'detailList',res.data.detailList);
                    this.data.errorMsg=res.data.errorMsg;
                    this.data.needSplit=res.data.needSplit;
                    //console.log(this.data);
                    
                }else{
                    //this.$Message.error(res.message);
                    //this.$bus.emit('bus_setsedit',{guid:item.guid,data:res.data})
                }
                
            })
         },split(item){
            this.$emit('bus_splitedit',item)
         },
         cancel(){
             this.modal=false;
         },sub(){
             var obj={
                 orderGuid:this.guid
             }
             if(this.data.needSplit=='Y'){
                 obj.itemGuids=this.data.detailList.map((i)=>{
                     if(i.check){
                         return i.guid;
                     }
                 })
             }
            this.axios.post('/outputinoivce/makeInvoiceByOrder',obj).then((res)=>{
                console.log(res);
                
                if(res.errorCode==0){
                     this.$Message.success(res.message);
                     this.$emit('refresh')
                     this.modal=false;
                 }else{
                     //this.$Message.error(res.message);
                 }
                
                
            })
         }
     },created(){
         this.$parent.$on('bus_setsedit', this.showdata);
         
     },beforeDestroy(){
         this.$parent.$off('bus_setsedit',this.showdata)
     }
 }
</script>
